package driver.nxt.events;

import icommand.nxt.SensorPort;
import icommand.nxt.SoundSensor;
import driver.events.Event;
import driver.exceptions.SensorException;

/**
 * Provides a mechanism for reading from the NXT Sound Sensor
 *
 * @author David Martin
 */
public class NXTSoundEvent extends Event
{

  private static final String EVENT_NAME = "Sound Sensor";
  private SoundSensor sensor;

  /**
   * Assigns the sensor port for the Sound sensor
   */
  public NXTSoundEvent()
  {
    super();
    sensor = new SoundSensor(SensorPort.S4);
  }

  public String getEventName()
  {
    return EVENT_NAME;
  }

  /**
   * Gets the next reading from the NXT Sound Sensor as a decibel value
   *
   * @return the sound sensor reading as decibels
   * @throws driversuite.exceptions.SensorException
   */
  public String readFromSensor() throws SensorException
  {
    return String.valueOf(sensor.getdB());
  }

  public String getMeasurementUnits()
  {
    return "dB";
  }
}
